/**
 * Created by Administrator on 2017/3/2 0002.
 */

var bool_click=true;

var Game={
    create:function () {
        var game={};

        game.ui=new PIXI.DisplayObjectContainer();

        var bg=new PIXI.Graphics();
        bg.beginFill(0xffffff,1);
        bg.drawRect(0,0,740,1136);
        bg.endFill();
        game.ui.addChild(bg);



        var sp_logo=Easy.CreateSprite('assets/images/logo.png',628,83,0.5,0.5,1);
        game.ui.addChild(sp_logo);

        var sp_title=Easy.CreateSprite('assets/images/title.png',366,188,0.5,0.5,1);
        game.ui.addChild(sp_title);


        var arr_piece=[];
        for(var i=0;i<10;i++)
        {
            var cp=CoverPiece.create('assets/images/'+i.toString(),250,400,i);
            arr_piece.push(cp);
        }
        var coverFlow=CoverFlow.create(arr_piece,Math.floor(arr_piece.length/2));
        game.ui.addChild(coverFlow.ui);
        coverFlow.ui.x=740/2;
        coverFlow.ui.y=450;

        var white=Easy.CreateSprite('assets/images/white.png',0,0,0.0,0.0,1);
        game.ui.addChild(white);

        var sp_t=Easy.CreateSprite('assets/images/t5.png',381,726,0.5,0.5,1);
        game.ui.addChild(sp_t);
        var sp_m=Easy.CreateSprite('assets/images/m5.png',370,774,0.5,0.5,1);
        game.ui.addChild(sp_m);


        var sp_tip=Easy.CreateSprite('assets/images/tip.png',367,1055,0.5,0.5,1);
        game.ui.addChild(sp_tip);

        document.getElementById('img_back').addEventListener('mousedown',backHandler);
        document.getElementById('img_back').addEventListener('touchstart',backHandler);

        var sp_bt=Easy.CreateSprite('assets/images/bt.png',367,971,0.5,0.5,1);
        game.ui.addChild(sp_bt);
        sp_bt.interactive=true;
        sp_bt.on('pointerdown',function () {
            //Out();
            sp_bt.interactive=false;

            document.getElementById('img_long').style.zIndex=10;
            TweenMax.to(document.getElementById('img_long').style,0.7,{top:pixiStage.scale.y*0+pixiStage.y+'px',opacity:1,ease:Cubic.easeOut});
            document.getElementById('img_qr').style.zIndex=11;
            TweenMax.to(document.getElementById('img_qr').style,0.7,{top:pixiStage.scale.y*0+pixiStage.y+'px',opacity:1,ease:Cubic.easeOut});

            document.getElementById('img_back').style.zIndex=12;
            document.getElementById('img_back').style.opacity=0;
            TweenMax.to(document.getElementById('img_back').style,0.7,{opacity:1,ease:Back.easeOut});
        });

        document.addEventListener('Game_Update',function (e) {
            console.log(e.detail)
            sp_t.texture=resource['assets/images/t'+e.detail+'.png'].texture;
            sp_m.texture=resource['assets/images/m'+e.detail+'.png'].texture;
        })
        document.addEventListener('Game_BigIn',function (e) {
            // canvas.width = window.innerWidth * 1;
            // canvas.height = window.innerHeight * 1;
            // canvas.style.width = window.innerWidth + 'px';
            // canvas.style.height = window.innerHeight + 'px';
            console.log('bigIn', e.detail)
            document.getElementById('div_2d').style.zIndex=0;
            document.getElementById('img_0').style.zIndex=5;
            document.getElementById('img_back').style.zIndex=6;
            document.getElementById('img_back').style.opacity=0;

            document.getElementById('img_0').src=e.detail;
            document.getElementById('img_0').style.opacity=0;
            document.getElementById('img_0').style.width= Math.floor(pixiStage.scale.x*740/ratio)+2+'px';
            document.getElementById('img_0').style.height= Math.floor(pixiStage.scale.y*1136/ratio)+2+'px';
            document.getElementById('img_0').style.left= pixiStage.scale.x*0+pixiStage.x+'px';
            document.getElementById('img_0').style.top= pixiStage.scale.y*0+pixiStage.y+'px';

            TweenMax.to(document.getElementById('img_back').style,0.7,{opacity:1,ease:Back.easeOut});
            TweenMax.to(document.getElementById('img_0').style,0.7,{top:pixiStage.scale.y*0+pixiStage.y+'px',opacity:1,ease:Cubic.easeOut});
        })

        function backHandler(e)
        {
            if(document.getElementById('img_back').style.opacity==1) {
                // canvas.width = window.innerWidth * ratio;
                // canvas.height = window.innerHeight * ratio;
                // canvas.style.width = window.innerWidth + 'px';
                // canvas.style.height = window.innerHeight + 'px';

                sp_bt.interactive=true;
                document.getElementById('img_back').style.opacity = 0;
                document.getElementById('img_0').style.opacity = 0;
                document.getElementById('img_0').style.zIndex = 0;
                document.getElementById('img_long').style.zIndex = 0;
                document.getElementById('img_qr').style.zIndex = 0;
                document.getElementById('img_back').style.zIndex = 0;
                document.getElementById('div_2d').style.zIndex = 5;
            }
        }

        document.getElementById('img_qr').addEventListener('touchmove',moveHandler);
        document.getElementById('img_qr').addEventListener('touchstart',startHandler);
        document.getElementById('img_0').addEventListener('touchstart',donMove);

        var preY=-1;
        var pageY=1;

        function donMove(e) {
            e.preventDefault();
        }

        function startHandler(e)
        {
            preY=e.touches[ 0 ].pageY;
        }
        function moveHandler(e)
        {
            e.preventDefault();
            if(preY!=1)
            {
                pageY+=4*(e.touches[0].pageY-preY);
                if(pageY>0)
                {
                    pageY=0;
                }
                else if(pageY<-747)
                {
                    pageY=-747;
                }
                document.getElementById('img_qr').style.top=pixiStage.scale.y/ratio*pageY+pixiStage.y+'px';
                document.getElementById('img_long').style.top=pixiStage.scale.y/ratio*pageY+pixiStage.y+'px';
                preY=e.touches[ 0 ].pageY;
            }

        }

        return game;
    }

}